package com.zzzy.server.controller;

import com.zzzy.common.vo.AjaxResult;
import com.zzzy.framework.common.dict.DictService;
import com.zzzy.framework.common.dict.dto.DictData;
import com.zzzy.framework.common.dict.dto.DictInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;


@Tag(name = "字典", description = "server003")
@Validated
@RestController
@RequestMapping("/dict")
public class DictController {

    @Resource
    private DictService dictService;

    @Operation(summary = "全部字典数据用于swagger给前端显示")
    @GetMapping(value = "/allDict")
    public AjaxResult<List<DictInfo>> allDict() {
        List<DictInfo> dictTypeList = dictService.getDictInfoList();
        return AjaxResult.success(dictTypeList);
    }

    @Operation(summary = "字典数据")
    @GetMapping(value = "/dictData/{dictType}")
    public AjaxResult<List<DictData>> dictData(@NotBlank(message = "字典类型不能为空") @PathVariable("dictType") String dictType) {
        List<DictData> dictDataList = dictService.getDictDataList(dictType);
        return AjaxResult.success(dictDataList);
    }
}
